<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<jsp:include page="../common/common.jsp"></jsp:include>
<style>
	
	#inner01{
		width:500px;
		height:600px;
		margin:100px auto;
		overflow: hidden;
		display: none;
	}
	#inner02{
		width:500px;
		height:600px;
		margin:100px auto;
		overflow: hidden;
		display: none;
	}

</style>

</head>
<body>
	<div id="main01">
		<table id="dg" ></table>  
	</div>
	
	<div id="td">
		<a href="#" id="myadd" class="easyui-linkbutton" data-options="iconCls:'icon-add'">添加</a>
		<a href="#" id="mydel" class="easyui-linkbutton" data-options="iconCls:'icon-remove'">删除</a>
		<a href="#" id="myupdate" class="easyui-linkbutton" data-options="iconCls:'icon-edit'">修改</a>
		<input type="text" name="searchName" id="sea" />
		<a href="#" id="mysearch" class="easyui-linkbutton" data-options="iconCls:'icon-search'">搜索</a>
	</div>
	
	<!-- 添加的弹出来的 -->
	<div id="dd">
		
		<div id="inner01">
	        
				 学生名字:<input name="name" class="easyui-validatebox" value="123" data-options="required:true,validType:''"  style="width:170px;height:20px"> 
				  <br/><br/>
				 学生学号:<input name="loginNo" class="easyui-numberbox" value="123" data-options="required:true,validType:''"  style="width:170px;height:20px"> 
					<br/><br/>
				 学生性别:<input type="radio" name="sex" value="1">男
					  <input type="radio" name="sex" value="0">女 
				  <br/><br/>
				 学生班级:<input id="cc01" name="grateName" value="01" width="174px"/>  
<!-- 				 学生班级:<input name="grateName" class="easyui-validatebox" value="123"  data-options="required:true,validType:''" style="width:170px;height:20px">  -->
					<!-- <br/><br/>
				 宿舍名称:<input name="dormitoryName" class="easyui-validatebox" value="123" data-options="required:true,validType:''" style="width:170px;height:20px"> 
					 -->
					 <br/><br/>
					 入住时间:<input class="easyui-datetimebox" id="beginTime" name="beginTime"     
        					data-options="required:true,showSeconds:false" id="dt1"   style="width:174px"> 
        		<br/><br/> 
				 宿舍名称:<input id="cc02" name="dormitoryName" value="01" width="174px"/> 
				 <br/><br/>
				 学生密码:<input name="password" class="easyui-validatebox" placeholder="默认密码123"  " style="width:170px;height:20px"> 
					<br/><br/>
					
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<a id="newadd" href="#" class="easyui-linkbutton" >添加</a>  
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<a id="cz" href="#" class="easyui-linkbutton" >重置</a>  
	      </div>
	
	</div>  
	
	<!-- 修改的弹出来的 -->
	<div id="dd2">
		
		<div id="inner02">
	        
	       				 <input type="text" name="id2" hidden="hidden"  />
				 学生名字:<input name="name2" class="easyui-validatebox"   style="width:170px;height:20px"> 
				  <br/><br/>
				 学生学号:<input name="loginNo2" class="easyui-validatebox"    style="width:170px;height:20px"> 
					<br/><br/>
				 学生性别:<input type="radio" name="sex2" value="1">男
					  <input type="radio" name="sex2" value="0">女 
				  <br/><br/>
				 学生班级:<input id="cc03" class="easyui-combobox" style="width:170px;height:20px" name="grateName2"   
   								 data-options="valueField:'id',textField:'name',url:'${pageContext.request.contextPath}/grade/getcommoBox'" />  

 
				  <br/><br/> 
				 入住时间:<input class="easyui-datebox" id="dt2" name="beginTime2"     
        	data-options="required:true,showSeconds:false"  style="width:174px">  

			
					 <br/><br/>
				 宿舍名称:<input id="cc04" class="easyui-combogrid" style="width:170px;height:20px"  name="dormitoryName2"  />  

				 <br/><br/>
				 学生密码:<input name="password2" class="easyui-validatebox" placeholder="默认密码123"  " style="width:170px;height:20px"> 
					<br/><br/>
					
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<a id="newupdate" href="#" class="easyui-linkbutton" >添加</a>  
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<a id="cz" href="#" class="easyui-linkbutton" >重置</a>  
	      </div>
	
	</div>  

	


<script type="text/javascript">

	$(function(){
		
		 /*选择班级*/
		$('#cc01').combogrid({    
				    panelWidth:250,    
				    value:'选择班级',    
				     
				    idField:'id',    
				    textField:'name',    
				    url:'${pageContext.request.contextPath}/grade/getcommoBox',
				    pagination : true,//是否分页  
			         rownumbers:true,//序号  
			         pageSize: 4,//每页显示的记录条数，默认为10  
			         pageList:[4,20,100],//可以设置每页记录条数的列表  
			         method:'post',     
				    columns:[[    
				           
				        {field:'name',title:'班级名称',width:150},    
				        {field:'teacher',title:'辅导员',width:100}    
				    ]]    
		});   
		

		/*选择宿舍*/
		$('#cc02').combogrid({    
		    panelWidth:550,    
		    value:'选择宿舍',    
		     
		    idField:'id',    
		    textField:'name',    
		    url:'${pageContext.request.contextPath}/dormitory/getcommoBox', 
		    pagination : true,//是否分页  
	         rownumbers:true,//序号  
	         pageSize: 4,//每页显示的记录条数，默认为10  
	         pageList:[4,20,100],//可以设置每页记录条数的列表  
	         method:'post',     
		    columns:[[    
		           
		        {field:'name',title:'宿舍名称',width:150},    
		        {field:'sex',title:'性别',width:100},    
		        {field:'counter',title:'可住人数',width:100},    
		        {field:'nowNum', title:'已入住人数',width:100},    
		    ]]    
		}); 
		
		/*修改下的宿舍*/
		$('#cc04').combogrid({    
		    panelWidth:550,    
		    value:'选择宿舍',    
		     
		    idField:'id',    
		    textField:'name',    
		    url:'${pageContext.request.contextPath}/dormitory/getcommoBox', 
		    pagination : true,//是否分页  
	         rownumbers:true,//序号  
	         
	         pageSize: 4,//每页显示的记录条数，默认为10  
	         pageList:[4,20,100],//可以设置每页记录条数的列表  
	         method:'post',     
		    columns:[[    
		           
		        {field:'name',title:'宿舍名称',width:150},    
		        {field:'sex',title:'性别',width:100},    
		        {field:'counter',title:'可住人数',width:100},    
		        {field:'nowNum', title:'已入住人数',width:100},    
		    ]]    
		}); 
		
		/*选择宿舍*/
		$('#cc04').combogrid({    
		    panelWidth:550,    
		    value:'选择宿舍',    
		     
		    idField:'id',    
		    textField:'name',    
		    url:'${pageContext.request.contextPath}/dormitory/getcommoBox',    
		    columns:[[    
		           
		        {field:'name',title:'宿舍名称',width:150},    
		        {field:'sex',title:'性别',width:100},    
		        {field:'counter',title:'可住人数',width:100},    
		        {field:'nowNum', title:'已入住人数',width:100},    
		    ]]    
		}); 
		
		
		/*数据表*/
		
		$('#dg').datagrid({    
		    url:'${pageContext.request.contextPath}/student/findWithPage',
		    fitColumns:true,
		   	/* singleSelect:true, */  
		    pagination:true,
		    toolbar:'#td',
		    pageNumber:1,
		    pageSize:4,
		    pageList:[4,8,16],
		    columns:[[    
		        {field:'id',title:'id',checkbox:true},    
		        {field:'name',title:'学生名字',width:100},    
		        {field:'loginNo',title:'学生学号',width:100},    
		        {field:'sex',title:'学生性别',width:100},    
		        {field:'grateName',title:'学生班级',width:100},    
		        {field:'dormitoryName',title:'宿舍名称',width:100},    
		        {field:'beginTime',title:'入住时间',width:100},    
		        {field:'password',title:'学生密码',width:100}  
		    ]]    
		});  

		/*总菜单 添加按钮*/
		
		$('#myadd').click(function(){
			
			$('#inner01').css("display","block");
			
			$('#dd').dialog({    
			    title: '添加',    
			    width: 800,    
			    height: 600,    
			    closed: false,    
			    cache: false,    
			    modal: true   
			});    
		});

		/*总菜单 添加按钮 弹出来的 提交按钮*/
		$('#newadd').click(function(){
			
			var a= $("input[name='name']").val();
			var b= $("input[name='loginNo']").val();
			var c=$('input:checked').val();
			var d= $('#cc01').combogrid('getText');
			var e= $('#cc02').combogrid('getText');
			var f= $("input[name='password']").val();
			var g= $('#dt1').datebox('getValue');	
			/*前端的判断*/
			if('选择班级'==d){
				$.messager.alert('提示','请选择班级'); 
				return false;
			}
			if('选择宿舍'==e){
				$.messager.alert('提示','请选择宿舍'); 
				return false;
			}
			
			if(undefined==c){
				$.messager.alert('提示','请选择性别'); 
				return false;
			}
			
			c= c==1?"男":"女";
			
			$.ajax({
				'type':'post',
				'dateType':'json',
				'url':'${pageContext.request.contextPath}/student/addStudent',
				'data':{
					'name':a,
					'loginNo':b,
					'sex':c,
					'grateName':d,
					'dormitoryName':e,
					'password':f,
					'beginTime':g,
				},
				'success':function(msg){
					if(msg.code==200){
						
						$.messager.alert('提示','插入成功');    
						
						setTimeout(goMain(), 1000);
					}else if(msg.code==303){
						$.messager.alert('提示',"学号已经存在"); 
					
					}else{
						$.messager.alert('提示','插入失败');    
					}
					
				},
			});
			 
		});
		
		/*总菜单删除的按钮 */
		$('#mydel').click(function(){
			var dels='';
			var obj=$('#dg').datagrid('getSelections');
			var a= $(obj).each(function(i,data){
				var aa=data.id;
				if(obj.length-1==i){
					dels=dels+aa;
				}else{
					dels=dels+aa+",";
				}
			});
			$.ajax({
				'type':'post',
				'dateType':'json',
				'url':'${pageContext.request.contextPath}/student/delStudent',
				'data':{
					'dles':dels,
					
				},
				'success':function(msg){
					if(msg.code==200){
						
						$.messager.alert('提示',"删除了"+msg.count+"条");
						setTimeout(goMain(), 1000);
					}else{
						$.messager.alert('提示',"删除失败");
					}
				},
			});
		});
		
		
		/*总菜单修改的按钮 */
		$('#myupdate').click(function(){
			
			/*只能选中一个*/
			var obj=$('#dg').datagrid('getSelections');
			if(obj.length==1){
				

				$('#inner02').css("display","block");
				/* 取到值 */
				var a= obj[0].id;
				var b= obj[0].name;
				var c= obj[0].loginNo;
				var d= obj[0].sex;
				var e= obj[0].grateName;
				var f= obj[0].dormitoryName;
				var g= obj[0].password;
				var h= obj[0].beginTime;
				
				if("男"==d){
					$("input[value='1']").attr("checked", "checked");
				}else{
					$("input[value='0']").attr("checked", "checked");
				}
				
				/* 赋值 */
				$("input[name='id2']").val(a);
				$("input[name='name2']").val(b);
				$("input[name='loginNo2']").val(c);
				$("input[name='sex2']").val(d);
				$("#cc03").combobox('select',e);
				/* $("input[name='grateName2']").val(e);  */
				$("#cc04").combogrid('setText',f);
				//checked="checked"
				$("input[name='password2']").val(g);
				$('#dt2').datebox('setValue',h);  
				$('#dd2').dialog({    
				    title: '修改',    
				    width: 800,    
				    height: 600,    
				    closed: false,    
				    cache: false,    
				    modal: true   
				});    
			}else{
				$.messager.alert('提示','只能修改的一个');    
			}
			
			
			
		});
		
		/*总菜单修改的按钮 弹出来的提交的按钮*/
		$('#newupdate').click(function(){
			
			var a=$("input[name='id2']").val();
			var b=$("input[name='name2']").val()
			var c=$("input[name='loginNo2']").val();
			var d=$("input[name='sex2']").val();
			
			
			var e= $('#cc03').combobox('getText');
			var f= $('#cc04').combogrid('getText');
			var g=$("input[name='password2']").val();
			var h= $('#dt2').datebox('getValue');	
			
			
			var pp=$('input[name=sex2]:checked').val();
			if(undefined==pp){
				$.messager.alert('提示','请选择性别'); 
				return false;
			}
			
			$.ajax({
				'type':'post',
				'dateType':'json',
				'url':'${pageContext.request.contextPath}/student/updateStudent',
				'data':{
					
					'id':a,
					'name':b,
					'loginNo':c,
					'sex':d,
					'grateName':e,
					'dormitoryName':f,
					'password':g,
					'beginTime':h,
				},
				'success':function(msg){
					if(msg.code==200){
						
						$.messager.alert('提示','更新成功'); 
						setTimeout(goMain(), 1000);
						
					}
					
				},
			});
			 
		});
		
		/*查询*/
		$('#mysearch').click(function(){
			var searchName1=$('#sea').val();
			
			$('#dg').datagrid('load', {    
			    'searchName':searchName1,
			});  


		});
		
		
/*结束*/
	});

		
	

	function goMain(){
		window.location.reload();
	}
	
	
</script>
</body>
</html>